//
//  ThirdViewController.m
//  UIComprehensive
//
//  Created by lanou3g on 16/1/25.
//  Copyright © 2016年 徐强. All rights reserved.
//

#import "ThirdViewController.h"
#import "TableViewController.h"
#import "CollectionViewController.h"
@interface ThirdViewController ()<UIScrollViewDelegate>

@end

@implementation ThirdViewController

-(void)loadView{
    self.rootView = [[ThirdView alloc]initWithFrame:([UIScreen mainScreen].bounds)];
    self.view = self.rootView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setDelegate];
    [self InitView];
}
- (void)InitView{
    self.title = @"ScrollView";
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithTitle:@"TableView" style:UIBarButtonItemStylePlain target:self action:@selector(leftAction:)];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"CollectionView" style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)];
    self.navigationItem.rightBarButtonItem = rightItem;
}
- (void)leftAction:(UIBarButtonItem *)sender{
    [self.navigationController pushViewController:[TableViewController new] animated:YES];
}
- (void)rightAction:(UIBarButtonItem *)sender{
    [self.navigationController pushViewController:[CollectionViewController new] animated:YES];
}

- (void)setDelegate{
    
    self.rootView.scrollV.delegate = self;
    self.rootView.scroll1.delegate = self;
    self.rootView.scroll2.delegate = self;
    self.rootView.scroll3.delegate = self;
    self.rootView.scroll4.delegate = self;
    self.rootView.scroll5.delegate = self;
    //pageControl
    [self.rootView.page addTarget:self action:@selector(actionPage:) forControlEvents:UIControlEventValueChanged];
}
#pragma mark -UIPageControl相应事件方法
- (void)actionPage:(UIPageControl *)sender{
    
    //currentPage当前页  根据currentPage找到计算图片对应偏移量寻找对应图片
    [self.rootView.scrollV setContentOffset:CGPointMake(300 *sender.currentPage, 0) animated:YES];
}
#pragma mark - scrollView 的代理方法
//设置进行缩放的视图，必须实现才能进行缩放, 只能缩放一张
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return scrollView.subviews[0];
}
//滑动时减速为零时调用的方法
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    //根据图片偏移量找到计算currentPage寻找对应图片
    self.rootView.page.currentPage = self.rootView.scrollV.contentOffset.x/300;
}
//结束拖拽时调用的方法
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    NSLog(@"%s",__FUNCTION__);
}
//结束缩放时调用的方法
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{
    NSLog(@"%s",__FUNCTION__);
}
//开始缩放的时候
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view{
    NSLog(@"%s",__FUNCTION__);
}





@end
